package com.xnyzc.lhy.order.controller.dapi.driver.wallet;


import com.xnyzc.lhy.common.entity.Rv;
import com.xnyzc.lhy.common.exception.PangException;
import com.xnyzc.lhy.common.penum.EErrorCode;
import com.xnyzc.lhy.common.util.CheckUtil;
import com.xnyzc.lhy.common.util.TokenUtil;
import com.xnyzc.lhy.order.service.driver.wallet.IOaDWalletService;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 司机钱包表 前端控制器
 * </p>
 *
 * @author zhuyubin
 * @since 2019-08-12
 */
@RestController
@RequestMapping("dapi/oaDWallet")
public class OaDWalletController {

    @Autowired
    private IOaDWalletService iOaDWalletService;

    @GetMapping(value = "getOaDWallet")
    public Rv getOaDWallet(){
        Long driverId = TokenUtil.getTokenUserId();
        if (CheckUtil.objIsEmpty(driverId)){
            throw PangException.create(EErrorCode.tokenExpire);
        }
        String tag = TokenUtil.getTag();
        if (CheckUtil.objIsEmpty(tag)){
            throw PangException.create(EErrorCode.missingAuthArgs);
        }
        return Rv.wrap(iOaDWalletService.getOaDWallet(driverId, tag));
    }

    @GetMapping(value = "selectOaDWalletRecordPage")
    public Rv selectOaDWalletRecordPage(@ApiParam(name = "type", value = "type") @RequestParam(value = "type") Integer type, @ApiParam(name = "current", value = "current") @RequestParam(value = "current") Long current){
        Long driverId = TokenUtil.getTokenUserId();
        if (CheckUtil.objIsEmpty(driverId)){
            throw PangException.create(EErrorCode.tokenExpire);
        }
        String tag = TokenUtil.getTag();
        if (CheckUtil.objIsEmpty(tag)){
            throw PangException.create(EErrorCode.missingAuthArgs);
        }
        if (CheckUtil.objIsEmpty(type) || CheckUtil.objIsEmpty(current)){
            throw PangException.create(EErrorCode.missingArg);
        }
        return Rv.wrap(iOaDWalletService.selectOaDWalletRecordPage(driverId, tag, type, current));
    }

    @GetMapping(value = "getOaDWalletRecord")
    public Rv getOaDWalletRecord(@ApiParam(name = "recordId", value = "recordId") @RequestParam(value = "recordId") Long recordId){
        Long driverId = TokenUtil.getTokenUserId();
        if (CheckUtil.objIsEmpty(driverId)){
            throw PangException.create(EErrorCode.tokenExpire);
        }
        String tag = TokenUtil.getTag();
        if (CheckUtil.objIsEmpty(tag)){
            throw PangException.create(EErrorCode.missingAuthArgs);
        }
        if (CheckUtil.objIsEmpty(recordId)){
            throw PangException.create(EErrorCode.missingArg);
        }
        return Rv.wrap(iOaDWalletService.getOaDWalletRecord(driverId, tag, recordId));
    }
}
